# -*- coding:utf-8 -*-
#! python3

# FaceCat-Python
#Shanghai JuanJuanMao Information Technology Co., Ltd 

from facecat_objc import *
		
#视图的鼠标按下方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseDown(view, mp, buttons, clicks, delta):
	onMouseDownDefault(view, mp, buttons, clicks, delta)
	global gMenu
	if buttons == 2:
		gMenu.location = view.paint.touchDownPoint
		gMenu.visible = True
		adjustMenu(gMenu)
		invalidate(gMenu.paint)

#视图的鼠标点击方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onClick(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks):
	onClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks)
	print(view.text)

gPaint = FCPaint() #创建绘图对象
gPaint.onMouseDown = onMouseDown 
gPaint.onClick = onClick
gMenu = None

#加载示例
def loadUI():
	global gMenu
	xml = """<?xml version="1.0" encoding="utf-8"?>
	<html xmlns="facecat">
	<head>
	</head>
	<body>
		<div dock="fill">
		</div>
	</body>
	</html>
	"""
	renderFaceCat(gPaint, xml)
	gMenu = FCMenu()
	gMenu.size = FCSize(100, 300)
	addView(gMenu, gPaint);
	for i in range(0, 10):
		menuItem = FCMenuItem()
		menuItem.text = "菜单项" + str(i + 1)
		menuItem.value = str(i + 1)
		addMenuItem(menuItem, gMenu)
		for j in range(0, 10):
			subMenuItem = FCMenuItem()
			subMenuItem.text = "子菜单项" + str(j + 1)
			subMenuItem.value = str(j + 1)
			addMenuItemToParent(subMenuItem, menuItem)
			for z in range(0, 10):
				sunMenuItem = FCMenuItem()
				sunMenuItem.text = "孙菜单项" + str(z + 1)
				sunMenuItem.value = str(z + 1)
				addMenuItemToParent(sunMenuItem, subMenuItem)

class AppDelegate(NSObject):
	def windowWillClose_(self, notification):
		os._exit(0)
	def applicationDidFinishLaunching_(self, notification):
		gPaint.size = FCSize(900, 770)
		window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
		NSMakeRect(0, 0, gPaint.size.cx, gPaint.size.cy),
		15,
		NSBackingStoreBuffered,
		False
		)
		window.setDelegate_(self)
		window.orderFrontRegardless()
		view = FCUIView.alloc().initWithFrame_(NSMakeRect(0, 0, gPaint.size.cx, gPaint.size.cy))
		view.paint = gPaint
		window.setContentView_(view)
		gPaint.view = view
		loadUI()

app = NSApplication.sharedApplication()
delegate = AppDelegate.alloc().init()
app.setDelegate_(delegate)
app.run()
